<div class="widget editor-widget">
	<div class="widget-header bg-blue">
		<i class="widget-icon icon-notebook"></i> 
		<span class="widget-caption"> 环信账号同步 </span>
		<div class="widget-buttons">
			<a href="javascript:void(0);" onclick="handlerCancel(this);" title="关闭"
				 data-toggle="dispose" data-refresh-table="#table-easemob"> <i class="fa fa-times"></i> </a> 
		</div>
	</div>
	<div class="widget-body">
		<!-- TODO 未注册环信的用户 -->
		<div class="widget radius-bordered mgbt-xs-10">
			<div class="widget-header">
				<i class="widget-icon icon-notebook"></i> 
				<span class="widget-caption"> 未注册环信的用户 </span>
			</div>
			<div class="widget-body editor-body-sm editor-body-neasemob">
				<div id="toolbar" class="btn-group">
			    <button type="button" class="btn btn-info" onclick="handlerSync();">
        		<i class="glyphicon glyphicon-refresh"></i> 一键同步
			    </button>
				</div>
				<table data-ajax="handlerSearch" 
   					 	 data-method="post" 
   					 	 data-toolbar="#btngroup" 
   					 	 data-id-field="id" 
   					 	 data-unique-id="id" 
   					 	 data-pagination="true" 
   					 	 data-check-on-init="true" 
   					 	 data-side-pagination="server" 
   					 	 data-mobile-responsive="true" 
   					 	 data-form-search="#search-form-neasemob" id="table-neasemob" class="bootstrap-table">
					<thead>
						<tr>
							<th data-field="id" 				data-visible="false" data-switchable="false">ID</th>
							<th data-field="shops" 			data-align="center" >机构</th>
							<th data-field="type" 			data-align="center" >身份</th>
							<th data-field="mobile" 		data-align="center" >手机</th>
							<th data-field="createDate" data-align="center" >时间</th>
						</tr>
					</thead>
				</table>
			</div>
		</div>
		
		<div class="widget radius-bordered mgbt-xs-10">
			<div class="widget-header">
				<i class="widget-icon icon-notebook"></i> 
				<span class="widget-caption"> 同步结果 </span>
			</div>
			<div class="widget-body editor-body-sm editor-body-neasemob">
				<ol id="sync-result"></ol>
			</div>
		</div>
	</div>
</div>

<!-- 查询表单 ========================================================= -->
<form id="search-form-neasemob" action="/miwawa/default/common/search.json" method="post" 
			name="com.app.miwawa.api.system.entity.view.NEasemobView">
			<input type="hidden" name="status" value="0" 				data-search-group="and" data-search-operation="EQ">
			<input type="hidden" name="invalid" value="F" 			data-search-group="and" data-search-operation="EQ">
			<input type="hidden" data-search-sort="createDate" 	data-search-order="desc">
			<input type="hidden" data-search-sort="id" 					data-search-order="asc">
</form>

<script type="text/javascript">
<!--
	jQuery(function(){
		handlerWebsocks();
		
		jQuery("#table-neasemob").bootstrapTable();
	});
	
	function handlerSync(){
		jQuery.utils.loading("正在同步环信账号，请稍后...", "show");
		jQuery.ajaxsend({
			url:"/miwawa/system/easemob/sync",
			success:function(data){
				jQuery.utils.loading(null, "hide");
			}
		});
	}
	
	function handlerWebsocks(){
		var websocket = null, server = /[^(http|https):\/\/]+[^(\/)]+/gi.exec(window.location.href)[0];
		
		if ('WebSocket' in window || 'MozWebSocket' in window) {
			websocket = new WebSocket("ws://"+server+"/miwawa/origin/websocket/synchs");
		} else {
			require(['sockjs'], function(sockjs){
				websocket = new SockJS("http://"+server+"/miwawa/sockjs/websocket/synchs");
			});
	 	}
		
		websocket.onopen = function(event){
			console.log(event);
		};
		
		websocket.onmessage = function(event) {
			jQuery("#sync-result").append("<li>"+event.data+"</li>");
    };
	}
//-->
</script>